package com.songlanyun.modules.category.controller.api;

import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.category.entity.SystemProductCategoryEntity;
import com.songlanyun.modules.category.service.SystemProductCategoryService;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 平台的商品分类表的控制层 api
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-02 15:58:00
 */
@RestController
@RequestMapping("api/category")
public class SystemProductCategoryApiController extends AbstractApiController {
    @Autowired
    private SystemProductCategoryService systemProductCategoryService;

    /**
     * 所有分类
     */
    @RequestMapping("/all")
    public R all() {
        List<Map<String, Object>> objs = systemProductCategoryService.getAllCategory();
        return R.ok().put("list", objs);
    }

    /**
     * 首页一级分类推荐
     */
    @RequestMapping("/home/recommend")
    public R homeRecommend(@RequestParam(value = "pid", required = false) Long parentId) {
        List<SystemProductCategoryEntity> list = systemProductCategoryService.homeRecommend(parentId);
        return R.ok().put("list", list);
    }
}

